package com.czd.support.service;

import com.czd.base.model.Paginate;
import com.czd.base.service.BaseService;
import com.czd.support.common.Configuration;
import com.czd.support.model.Advertising;
import org.springframework.stereotype.Service;

/**
 * 功能说明：广告位Service
 * 作者：liuxing(2014-12-20 23:19)
 */
@Service
public class AdvertisingService extends BaseService<Advertising> {

    /**
     * 新增一个广告位配置，返回主键
     * @param roomId
     * @param advImg
     * @param link
     * @param positionCode
     * @param creator
     * @param updator
     * @return
     */
    public int insertAndReturnId(Integer roomId, String advImg, String link, String positionCode, int creator, int updator) {
        Advertising insertBean = new Advertising();
        insertBean.setRoomId(roomId);
        insertBean.setAdvImg(advImg);
        insertBean.setLink(link);
        insertBean.setPositionCode(positionCode);
        insertBean.setCreator(creator);
        insertBean.setUpdator(updator);
        return super.insertAndReturnId(sqlId("insertAndReturnId"), insertBean);
    }

    /**
     * 新增一个广告位配置
     * @param roomId
     * @param advImg
     * @param link
     * @param positionCode
     * @param creator
     * @param updator
     * @return
     */
    public boolean insert(Integer roomId, String advImg, String link, String positionCode, int creator, int updator) {
        return this.insertAndReturnId(roomId, advImg, link, positionCode, creator, updator) > 0;
    }

    /**
     * 查询分页
     * @param pageNo
     * @return
     */
    public Paginate queryForPaginate(int pageNo){
        Advertising queryBean = new Advertising();
        queryBean.setPageNo(pageNo);
        queryBean.setPageSize(Configuration.getInstance().getDefault_page_size());
        return this.queryForPaginate(sqlId("queryForPaginate"), sqlId("count"), queryBean);
    }

    /**
     * 根据主键查询广告详细信息
     * @param id
     * @return
     */
    public Advertising findById(int id) {
        return super.selectOneById(sqlId("findById"), id);
    }

    /**
     * 修改广告位配置
     * @param id
     * @param roomId
     * @param advImg
     * @param link
     * @param positionCode
     * @param updator
     * @return
     */
    public boolean update(int id, Integer roomId, String advImg, String link, String positionCode, int updator) {
        Advertising updateBean = new Advertising();
        updateBean.setId(id);
        updateBean.setRoomId(roomId);
        updateBean.setAdvImg(advImg);
        updateBean.setLink(link);
        updateBean.setPositionCode(positionCode);
        updateBean.setUpdator(updator);
        return super.update(sqlId("update"), updateBean);
    }
}
